package com.ruoyi.mine.controller;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.mine.pojo.Mine;
import com.ruoyi.mine.service.MinesService;
import com.ruoyi.mine.vo.MinesInfoByProvinceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "矿山信息管理相关接口", value = "矿山信息空间搜索逻辑不明,(PostgreSQL主导执行)已完成全部接口测试")
@RestController
@RequestMapping("/mine/info")
public class MinesController {

    @Autowired
    private MinesService minesService;

    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation(value = "矿山信息添加接口")
    @PostMapping("/add")
    public R<String> add(@RequestBody Mine mine){

        minesService.add(mine);
        return R.ok("矿山信息添加成功");
    }

    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation(value = "矿山信息删除接口")
    @DeleteMapping("/delete")
    public R<String> delete(@RequestParam("mineId") String mineId){

        minesService.delete(mineId);
        return R.ok("矿山信息删除成功");
    }

    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation(value = "矿山信息更新接口")
    @PutMapping("/update")
    public R<String> update(@RequestBody Mine mine){

        minesService.update(mine);
        return R.ok("矿山信息更新成功");
    }

    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation(value = "矿山信息查询接口")
    @PostMapping("/search")
    public R<List<Mine>> search(@RequestBody Mine mine
    ){

        List<Mine> mines = minesService.search(mine);
        return R.ok(mines,"矿山信息查询成功");
    }

    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation(value = "查询所有矿山信息", notes = "已完成对于自定义异常填写;未测试")
    @GetMapping("/searchAllInfo")
    public R<List<Mine>> all(){

        List<Mine> mines = minesService.searchAll();
        return R.ok(mines,"所有矿山信息查询成功");
    }

    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation(value = "查询所有矿山信息按照省份分组接口")
    @GetMapping("/searchAllByProvince")
    public R<List<MinesInfoByProvinceVO>> searchByProvince(){

        List<MinesInfoByProvinceVO> mines = minesService.searchByProvince();
        return R.ok(mines,"所有矿山信息按照省份分组查询成功");
    }

    /**
     * 剩余一个接口将获取到的数据按照省份分组，并返回每个省份的全部查询数据
     * 例：响应示例为：
     * {
     *   "code": 200,
     *   "data": [
     *     {
     *       "province": "内蒙古",
     *       "mines": [
     *         {
     *           "mine_id": "string",
     *           "mine_name": "string",
     *           "mine_type": 0,
     *           "mine_province": "string",
     *           "mine_market": "string",
     *           "mine_county": "string",
     *           "mine_elevation_lower": 0,
     *           "mine_elevation_upper": 0,
     *           "mine_status": 0,
     *           "primary_contact_name": "string",
     *           "primary_contact_phone": "string",
     *           "dispatch_office_phone": "string",
     *           "boundary_polygon": {
     *             "type": "Polygon",
     *             "coordinates": [
     *               [
     *                 [
     *                   82.50401171164975,
     *                   42.225362693197724
     *                 ],
     *                 [
     *                   82.49217696840432,
     *                   42.225402241505
     *                 ],
     *                 [
     *                   82.48745443627566,
     *                   42.23179111299096
     *                 ],
     *                 [
     *                   82.48618101345963,
     *                   42.25144408137422
     *                 ],
     *                 [
     *                   82.51608246882117,
     *                   42.25401091419633
     *                 ],
     *                 [
     *                   82.53512218595037,
     *                   42.25562964125471
     *                 ],
     *                 [
     *                   82.50401171164975,
     *                   42.225362693197724
     *                 ]
     *               ]
     *             ]
     *           },
     *           "green_mine_level": "string",
     *           "reclamation_rate": 0,
     *           "ecological_quality": 0
     *         }
     *       ]
     *     }
     *   ]
     * }
     */
}
